package com.keqiang.chart.impl.axis.impl.pseudo3d.bar

import android.graphics.Canvas
import com.keqiang.chart.base.BaseChartView
import com.keqiang.chart.impl.axis.AxisEntity
import com.keqiang.chart.impl.axis.BaseAxisChart3D
import com.keqiang.chart.impl.axis.BaseTouchHandler
import com.keqiang.chart.impl.axis.BaseXAxis
import com.keqiang.chart.impl.axis.XAxis
import com.keqiang.chart.impl.axis.XAxis3D
import com.keqiang.chart.impl.axis.YAxis
import com.keqiang.chart.impl.axis.impl.bar.BarData
import com.keqiang.chart.impl.axis.impl.bar.BarEntity
import com.keqiang.chart.impl.axis.render.BaseDataRender
import com.keqiang.chart.impl.axis.render.XAxisRender
import com.keqiang.chart.impl.axis.render.YAxisRender

/**
 * 柱状图
 *
 * @author Created by wanggaowan on 2022/7/29 15:15
 */
open class BarChart3D(view: BaseChartView<*>) : BaseAxisChart3D<BarData>(view) {
    override var xAxis: XAxis3D = XAxis3D()
    override var yAxis: YAxis = YAxis()
    override var yAxisRender: YAxisRender<BarChart3D> = Bar3DYAxisRender(this)
    override var xAxisRender: XAxisRender<BarChart3D> = Bar3DXAxisRender(this)
    override var dataRender: BaseDataRender<BarChart3D> = BarChart3DataRender(this)
    override var touchHandler: BaseTouchHandler<BarChart3D, List<BarEntity>>? =
        Bar3DTouchHandler(this)

    var highLightRender: HighLightRender? = null

    override fun getGridWidth(xAxis: BaseXAxis, xAxisLength: Float): Float {
        return xAxisLength / xAxis.labelCount
    }

    override fun isEmptyData(): Boolean {
        return data == null
    }
}


/**
 * 高亮数据绘制器
 *
 * @author Created by wanggaowan on 2022/11/1 10:07
 */
abstract class HighLightRender(val chart: BarChart3D) {
    /**
     * 绘制高亮内容，此时[AxisEntity.drawRectF]已就绪
     *
     * @param canvas 画布
     * @param start  水平可绘制区域起始点坐标 = x轴起始点 + [XAxis.startPadding]
     * @param top    可绘制区域顶部坐标 = y轴顶部 - [YAxis.endPadding]
     * @param end    水平可绘制区域结束点坐标 = x轴结束点 - [XAxis.endPadding]
     * @param bottom 可绘制区域底部坐标 = y轴底部 + [YAxis.startPadding]
     */
    abstract fun onDraw(canvas: Canvas, start: Float, top: Float, end: Float, bottom: Float, data: List<BarEntity>)
}
